#ifndef  __TLGAPP__
#define  __TLGAPP__

#include "LinuxBase.h"

#ifndef ITEMSIZE
	#define ITEMSIZE(p) (sizeof(p)/sizeof(p[0]))
#endif

typedef struct _tlg_siginf
{
	int  nSig;
	int  nParam;
	long lParam;
}TLG_SIGINF;

typedef void (*TLG_HOOKSIG)(int,long);

class CTlgApp
{
public:
	CTlgApp();
	virtual ~CTlgApp();
	
	bool SetHigHook(int nSig,TLG_HOOKSIG pFunc);

	virtual bool InitApp(int argc,char *argv[]);
	virtual bool PeekMessage();

	bool IsRunning();
	void SetRunning(bool bRun);

	CString GetModuleFileName();
	CString GetExeFileName();
	CString GetRunDir();

	virtual CString DefaultAppName();
	
	virtual bool InitInstance();
	virtual int  ExitInstance();
	virtual int  Run();
	virtual bool DoLoopStep() {return false;}
	virtual void OnAppExit(){}

public:
	int m_argc;
	char **m_argv;
	
protected:
	virtual bool TranslateMessage(TLG_SIGINF &msg);

	virtual void OnSigTerm ();
	virtual void OnSigInt  ();
	virtual void OnSigChild(int nPid,long lStatus);
	virtual void OnSigUsr1 ();
	virtual void OnSigUsr2 ();

	virtual void OnIdle() {}

protected:
	CString m_szRunPath;
	CString m_szAppName;
	bool m_bRunning;
};

CTlgApp* TlgGetApp();

#endif //__TLGAPP__

